﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NPOI.SS.Formula.Eval;
using Text.IBll;
using Text.Model;
using Text.Model.Shop;
using Text.Model.ShopModel;

namespace TextApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        IAdminBll bll;

        public UserController(IAdminBll bll)
        {
            this.bll = bll;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="t">某个实体</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<int> ADD(AdminModel t)
        {
            return await bll.ADD(t);
        }
        /// <summary>
        /// 显示列表
        /// </summary>
        /// <returns>返回所查询的数据</returns>
        [HttpGet]
        public IQueryable<AdminModel> GetModel(string? name="", int? min = null, int? max = null, DateTime? da1 = null, DateTime? da2 = null)
        {
            return bll.GetModel(name,min,max,da1,da2);
        }
        [HttpPost]
        public async Task<int> ShopAdd(ShopModel t)
        {
            try
            {
                return await bll.ShopAdd(t);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpGet]
        /// <summary>
        /// 门店添加
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public IQueryable<Address> GetAddr()
        {
            try
            {
                return bll.GetAddr();
            }
            catch (Exception)
            {

                throw;
            }
           
        }
        [HttpGet]
        public IActionResult GetShop( int pageindex = 1, int pagesize = 2, string? shopName = "", int? address = null)
        {
            try
            {
                int totalcount = 0;  int totalpage = 0;
                var list = bll.GetShop(out totalcount, out totalpage, pageindex, pagesize, shopName, address);
                return Ok(
                new
                {
                    totalcount = totalcount,
                    totalpage = totalpage,
                    list = list,
                }
                );
               
            }
            catch (Exception)
            {

                throw;
            }
        }


    }
}
